import java.awt.image.BufferedImage;
import java.io.*;

import javax.imageio.ImageIO;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.Reader;  // Reader is an interface
import com.google.zxing.NotFoundException;  // Reader's exception
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.MultiFormatReader;  // Reader's implementation
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;


public class driver {
	public static void main(String[] args) {
		InputStream barCodeInputStream;
		for(int i = 1; i <= 7; i++ ){
			try {
				barCodeInputStream = new FileInputStream("./image/" + Integer.toString(i) + ".png");
				BufferedImage barCodeBufferedImage;
				barCodeBufferedImage = ImageIO.read(barCodeInputStream);
				LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
				BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
				Reader reader = new MultiFormatReader();
				try{
					Result result = reader.decode(bitmap);
					System.out.println("barcode " + i + " , result is:" );
					System.out.println(result.getText());
				}
				catch(NotFoundException|FormatException|ChecksumException e){
					System.out.println("Exception happens, from Reader.");
				}
			} catch (IOException e) {
				System.out.println("Exception happens, from FileInputStream/ImageIO.");
			}
		}
	}
}
